﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Fis.Win.Utils
{
    public class SchemaUtils
    {
        public DataTable ReadSchema(string table)
        {
            DataSet ds = new DataSet();
            Agile.Engine.Data.DataAccess da = new Agile.Engine.Data.DataAccess();
            da.Context = Agile.Engine.Data.DataContext.Get("CacheDataContext");
            da.TableName = table;
            return da.GetSchema();
        }

        public void SaveSchema(string table)
        {
            var data = ReadSchema(table);
            data.ExtendedProperties["type"] = this.GetType();
            data.WriteXmlSchema("C:\\" + table + ".xml");
        }

        public static DataTable LoadSchema(string table)
        {
            DataTable data = new DataTable();
            var stream = Agile.Engine.Utils.IOUtils.InputStream(string.Format("assembly://Agile.Engine.Config/Agile.Engine.Config.Schema/{0}.xml", table));
            data.ReadXmlSchema(stream);
            return data;
        }

    }
}
